package com.smart.parking.controller.backstage;

import java.util.Arrays;
import java.util.Map;

import com.smart.parking.config.Result;
import com.smart.parking.entity.ChargeEntity;
import com.smart.parking.service.ChargeService;
import com.smart.parking.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 停车收费表
 *
 * @author ciyun
 * @email ciyun@gmail.com
 * @date 2022-10-30 14:12:09
 */
@RestController
@RequestMapping("/back/charge")
public class ChargeController {
    @Autowired
    private ChargeService chargeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = chargeService.queryPage(params);

        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{chargeId}")
    public Result info(@PathVariable("chargeId") Long chargeId){
		ChargeEntity charge = chargeService.getById(chargeId);

        return Result.ok().put("charge", charge);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody ChargeEntity charge){
		chargeService.save(charge);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody ChargeEntity charge){
		chargeService.updateById(charge);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] chargeIds){
		chargeService.removeByIds(Arrays.asList(chargeIds));

        return Result.ok();
    }

}
